package com.example.zuoye;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.Arrays;

public class MyclassActivity extends AppCompatActivity {

    private String[] texts=new String[]{"Android开发技术","软件设计与体系结构","JavaWeb开发技术","高等数学","商务英语","中国近现代史纲要"};
    //要展示的图
    private Integer[] images=new Integer[]{
            R.mipmap.aixin,
            R.mipmap.biji,
            R.mipmap.xiezi,
            R.mipmap.diandeng,
            R.mipmap.chayue,
            R.mipmap.pingguo
    };

    //定义ListView组件
    ListView mListView=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myclass);
        mListView=(ListView) findViewById(R.id.listview);


        //创建适配器，用的是自定义TextImageAdapter
        MyAdapter adapter=new MyAdapter(this, Arrays.asList(texts),Arrays.asList(images));

        mListView.setAdapter(adapter);

        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(MyclassActivity.this,"您选择了"+texts[position],Toast.LENGTH_LONG).show();
            }
        });

    }
}
